<!--左侧登陆组件-->
<aside id="zan_login-5">
    <div class="panel panel-zan" aos="flip-right" aos-duration="3000">
        <div class="panel-heading">请登录</div>

        <%
        if(login){
        %>
            <div class="login-panel text-center">


                <img src="<%=avatar%>"+ width="54" height="54" alt="" id="selfavatar" class="avatar avatar-60 wp-user-avatar wp-user-avatar-60 photo avatar-default">

           


                <a class="user-name" href="#wp-admin/">
                    <%= username %>
                </a>
                <a class="btn btn-inverse-primary logout"  title="退出登录">退出登录</a>                </div>


            <%
              }else{
             %>
                <form class="login-form clearfix">
                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-addon"><i class="fa fa-user"></i></div>
                            <input class="form-control" type="text" name="log" id="log" value="" size="20" /> </div>
                    </div>
                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-addon"><i class="fa fa-lock"></i></div>
                            <input class="form-control" type="password" name="pwd" id="pwd" size="20" /> </div>
                    </div>
                    <p><label for="rememberme"><input name="rememberme" type="checkbox" id="rememberme" value="forever" /> 记住我的登录信息</label>
                        <!--<a title=" Password Lost and Found" style="color: #3d4450;float:right;font-weight:bold;padding:2px;">忘记密码？</a>-->
                    </p>

                    <a  class="btn btn-inverse-primary pull-right startreg">可以先注册</a>
                    <button class="btn btn-inverse-primary pull-left" id="login" type="button">登录</button>
                </form>

                <%
                  }
                %>
    </div>
</aside>

<script>
    jQuery('.startreg').click(function(){
        window.location="/reg?nowurl="+nowurl
    })
    jQuery(".logout").click(function(){
        jQuery.get("/login/logout",{},function(res){
            if(res.status==200){
                window.location = nowurl;
            }
        })
    })
    jQuery('.avatar').click(function(){
      let that = this;
      uploadAction({
        url:'/uploadheader',
        success: function(result) {
          
          if (
            result &&
            result.success &&
            result.data &&
            result.data.pictureUrl
          ) {
            jQuery('.avatar').attr("src",result.data.pictureUrl)
         //   that.$store.commit("updateavatar", result.data.pictureUrl);
          }
        },

      });
    })
    jQuery('#login').click(function () {

        jQuery.post("/login", {
            "username": jQuery('#log').val(),
            "password": jQuery("#pwd").val()
        }, function (res) {
            if (res == "1") {
               
               window.location = nowurl;
            } else if (res == "-1") {
                //用户名不存在

                console.log("用户名不存在！");
            } else if (res == "-2") {
                //密码错误
                console.log("密码错误");
            }
        })
    })



    //   var files = e.target.files || e.dataTransfer.files;
    //   if (!files.length)return;
    //   var txPhoto = files[0];

    //   //去上传
    //   let file = e.target.files[0];           


    //   let $img = document.getElementById("tx_img");
    //   var windowURL = window.URL || window.webkitURL;
    //   var dataURL = windowURL.createObjectURL(files[0]);
    //   var imgurl = response.data.data[0].headimg;
    //  $img.src =

</script>